#include "EnemyActionFactory.h"
#include <string>
#include "pugixml.hpp"

using namespace std;
using namespace pugi;

EnemyActionFactory::EnemyActionFactory(void)
{
}


EnemyActionFactory::~EnemyActionFactory(void)
{
}

EnemyActionFactory* EnemyActionFactory::sharedActionFactory()
{
	if (!_instance)
		_instance = new	EnemyActionFactory();
	return _instance;
}

void EnemyActionFactory::initFactory()
{

}

void EnemyActionFactory::clearFactory()
{
	CC_SAFE_DELETE(_instance);
	_instance = NULL;
}

CCAction* EnemyActionFactory::createAction( char* _id, std::string data )
{
	CCAction* action = NULL;
	string id = _id;
	xml_document doc;
	xml_parse_result result = doc.load(data.c_str());

	if (id == "rotate")
	{
		float time = doc.child("Data").child("Time").text().as_float();
		CCAction* ac = CCRotateBy::create(time, 360);
		action = CCRepeatForever::create((CCActionInterval*)ac);
	}

	return action;
}

EnemyActionFactory* EnemyActionFactory::_instance = NULL;
